---
title: Self Hosting (Copilot Runtime)
description: Learn how to self-host the Copilot Runtime.
icon: "lucide/Server"
---

import SelfHostingCopilotRuntimeCreateEndpoint from "@/snippets/self-hosting-copilot-runtime-create-endpoint.mdx";
import SelfHostingCopilotRuntimeConfigureCopilotKitProvider from "@/snippets/self-hosting-copilot-runtime-configure-copilotkit-provider.mdx";
import LLMAdapters from "@/snippets/llm-adapters.mdx";

The Copilot Runtime is the back-end component of CopilotKit, handling the communication with LLM, message history, state and more.

You may choose to self-host the Copilot Runtime, or [use Copilot Cloud](https://cloud.copilotkit.ai) (recommended).

<Frame>
  <div className="w-full pb-4">
  ```mermaid
  sequenceDiagram
    participant core as @copilotkit/react-core
    participant runtime as Copilot Runtime
    participant llm as LLM

    core->>runtime: "Hey, my name is Uli."
    runtime->>llm: Request
    llm->>runtime: Response
    runtime->>core: "Hello Uli, how can I help you?"

````
</div>
</Frame>


## Integration

<Steps>
<Step>
  ### Step 1: Create an Endpoint
  <SelfHostingCopilotRuntimeCreateEndpoint components={props.components} />
</Step>

<Step>
  ### Step 2: Get Your Copilot Cloud API Key (Optional but Recommended)

  <Callout type="info">
    While self-hosting, you can still leverage Copilot Cloud's enhanced features for production-ready deployments.
  </Callout>

  1. Go to [Copilot Cloud](https://cloud.copilotkit.ai) and sign up for free
  2. Get your API key from the dashboard
  3. Add it to your environment variables:

  ```plaintext title=".env"
  COPILOT_CLOUD_PUBLIC_API_KEY=your_api_key_here
  ```

  **Why add this?**
  - **Free tier available** - Your requests will NOT be logged
  - **Production-ready features** - Enhanced error handling and observability
  - **Developer console** - Better debugging and monitoring (coming soon)
  - **Error observability** - Track and debug issues in production

  This enables CopilotKit platform features while still using your self-hosted runtime.
</Step>

<Step>
  ### Step 3: Configure the `<CopilotKit>` Provider
  <SelfHostingCopilotRuntimeConfigureCopilotKitProvider components={props.components} />
</Step>

</Steps>

## Next Steps

- [`CopilotRuntime` Reference](/reference/classes/CopilotRuntime)
- [LLM Adapters](/reference/classes/llm-adapters/OpenAIAdapter)
````
